#!/usr/bin/env python3
# -*- coding: utf-8 -*-

#读取channelinfolist.conf
import codecs 
import configparser
import string, os, sys

class ChannelObject(object):
	def __init__(self,channelname,woshopid,egame_channel,umeng_channel,l_channel,l_appid,refpropath,channeloperfilepath,wxappid,wxappsecret,packagename,soulgame_channel,dksdk_channel,wxlogin):
		self.__channelobj = {}
		self.__channelobj["woshopid"] = woshopid
		self.__channelobj["egame_channel"] = egame_channel
		self.__channelobj["umeng_channel"] = umeng_channel
		self.__channelobj["l_channel"] = l_channel
		self.__channelobj["l_appid"] = l_appid
		self.__channelobj["refprojectpath"] = refpropath.replace("\\","/")
		self.__channelobj["channeloperfilepath"] = channeloperfilepath.replace("\\","/")
		self.__channelobj["wxappid"] = wxappid
		self.__channelobj["wxappsecret"] = wxappsecret
		self.__channelobj["packagename"] = packagename
		self.__channelobj["soulgame_channel"] = soulgame_channel
		self.__channelobj["dksdk_channel"] = dksdk_channel
		self.__channelobj["wxlogin"] = wxlogin

	def getChannelInfo(self):
		return self.__channelobj

class ChannelConfigReader(object):
	def __init__(self,configfilepath):
		self.__configfilepath = configfilepath		
		self.__configreader = configparser.ConfigParser()
		self.__channelinfodict = {}

		if(False == os.path.exists(self.__configfilepath)):
			raise Exception(self.__configfilepath + " 文件不存在,初始化失败!")

		fp = codecs.open(self.__configfilepath, "rb", "utf-8")
		self.__configreader.readfp(fp)
		#self.__configreader.read(self.__configfilepath)
		secs = self.__configreader.sections()	
		for sec in secs:
			channelname = sec
			woshopid = self.__configreader.get(channelname,"woshopid")
			egame_channel = self.__configreader.get(channelname,"egame_channel")
			umeng_channel = self.__configreader.get(channelname,"umeng_channel")
			l_channel = self.__configreader.get(channelname,"l_channel")
			l_appid = self.__configreader.get(channelname,"l_appid")
			refpropath = self.__configreader.get(channelname,"refprojectpath")
			channeloperfilepath = self.__configreader.get(channelname,"channeloperfilepath")
			wxappid = self.__configreader.get(channelname,"wxappid")
			wxappsecret = self.__configreader.get(channelname,"wxappsecret")
			packagename = self.__configreader.get(channelname,"packagename")
			soulgame_channel = self.__configreader.get(channelname,"soulgame_channel")
			dksdk_channel = self.__configreader.get(channelname,"dksdk_channel")
			wxlogin = self.__configreader.get(channelname,"wxlogin")
			
			channelinfo = ChannelObject(channelname,woshopid,egame_channel,umeng_channel,l_channel,l_appid,refpropath,channeloperfilepath,wxappid,wxappsecret,packagename,soulgame_channel,dksdk_channel,wxlogin)
			self.__channelinfodict[channelname] = channelinfo

	def getConfigDict(self):
		return self.__channelinfodict

if __name__=="__main__":
	channelRd = ChannelConfigReader("./userconfig/channelinfolist.conf")

	channeldict = channelRd.getConfigDict()
	for channelname in channeldict:
		channelinfo = channeldict[channelname].getChannelInfo()
		print("----------------",channelname,"----------------")
		print(channelinfo["woshopid"])
		print(channelinfo["egame_channel"])
		print(channelinfo["umeng_channel"])
		print(channelinfo["l_channel"])
		print(channelinfo["l_appid"])
		print(channelinfo["refprojectpath"])
		print(channelinfo["channeloperfilepath"])
		print(channelinfo["wxappid"])
		print(channelinfo["wxappsecret"])
		print(channelinfo["packagename"])
		print(channelinfo["soulgame_channel"])
		print(channelinfo["dksdk_channel"])
		print(channelinfo["wxlogin"])
		
		